/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package idoms;

import java.util.List;

/**
 *
 * @author Ngocvan
 */


//dont use repeated string concatenation
//StringBuilder >> StringBuffer
public class JoinString {
    // join(["a", "b", "c"]) -> "a and b and c"
    static String join( List<String> strs){
        StringBuilder sb = new StringBuilder("");
        boolean first = true;
        for (String string : strs) {
            if (first){
                first = false;
            } else {
                sb.append(" and ");
            }
            sb.append(string);
        }
        return sb.toString();
    }
}
